#!/bin/bash
# 备份数据库并保存到Git

# 数据库信息
DB_USER="root"
DB_PASS="12345678" 
DB_NAME="moten"

# 备份文件存放位置
BACKUP_DIR="/Users/renliangzhang/zhangrl/mysql-backups"

# 创建备份
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/backup.sql

# 提交到Git
cd $BACKUP_DIR
git add backup.sql
git commit -m "数据库备份 $(date +'%Y-%m-%d %H:%M')"
git push origin master



# 备份恢复
# mysql -u用户名 -p 数据库名 < /home/你的用户名/mysql_backups/backup.sql